package com.edgclub.edg.uc;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.edgclub.edg.R;

/**
 * 左侧的选项
 * 
 * @author 陈坤彬
 *
 */
public class SetUpLayout extends LinearLayout {

	// 图标
	private ImageView icon;

	// 文字
	private TextView textView;

	private int text;
	private int image;
	private boolean isvise;

	public SetUpLayout(Context context, AttributeSet attrs) {
		super(context, attrs);

		initView(context, attrs);
	}

	public void initView(Context context, AttributeSet attrs) {
		LayoutInflater.from(context).inflate(R.layout.layout_setup_item, this);

		icon = (ImageView) findViewById(R.id.icon);
		textView = (TextView) findViewById(R.id.text);

		TypedArray array = context.obtainStyledAttributes(attrs,
				R.styleable.SetUpLayout);

		isvise = array.getBoolean(R.styleable.SetUpLayout_visable, false);
		if(isvise){
			icon.setVisibility(GONE);
		}else{
			icon.setVisibility(VISIBLE);
		}

		image = array.getResourceId(R.styleable.SetUpLayout_setupicon,
				R.drawable.ic_gz_about_guzhi_s);

		text = array.getResourceId(R.styleable.SetUpLayout_setuptext,
				R.string.app_name);

		if (null != icon) {
			icon.setBackgroundResource(image);
			icon.setSelected(true);
		}
		if (null != textView) {
			try {
				textView.setText(text);
			} catch (Exception e) {
				e.printStackTrace();
				textView.setText("");
			}
		}

		array.recycle();
	}

	public ImageView getIcon() {
		return icon;
	}

	public void setIcon(ImageView icon) {
		this.icon = icon;
	}

	public TextView getTextView() {
		return textView;
	}

	public void setText(TextView textView) {
		this.textView = textView;
	}

	public int getText() {
		return text;
	}

	public void setText(int text) {
		this.text = text;
	}

	public int getImage() {
		return image;
	}

	public void setImage(int image) {
		this.image = image;
	}

}
